package com.ky.homestay.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Homestay 全局常量
 */
@Configuration
public class HomestayWebMvcConfigurer implements WebMvcConfigurer {

    /**
     * 自定义拦截器
     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //注册TestInterceptor拦截器
//        InterceptorRegistration registration = registry.addInterceptor(new AdminInterceptor());
//        //所有路径都被拦截
//        registration.addPathPatterns("/**");
//        //白名单
//        registration.excludePathPatterns(
//                "/login",
//                HomestayConstant.SERVER_PATH,
//                "/common/*",
//                "/error/**",
//                "/image/**",
//                "/css/**",
//                "/js/**",
//                "/lib/**",
//                "/**/*.js",
//                "/**/*.css",
//                "/**/*.woff",
//                "/**/*.xhtml",
//                "/**/*.ttf"
//        );
//    }
	 
    /**
     * 虚拟目录
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //虚拟映射目录
		//registry.addResourceHandler("访问路径").addResourceLocations("磁盘路径");
//配置静态文件路径，免拦截,开启这行，所有接口都先匹配静态文件，找不到再找接口。
//        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/").addResourceLocations("classpath:/resources/");
        registry.addResourceHandler("/image/**").addResourceLocations("classpath:/static/image/");
        registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
        registry.addResourceHandler("/lib/**").addResourceLocations("classpath:/static/lib/");
        registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/static/favicon.ico");
    }
	 
}
